package com.gjw.cor;

import com.gjw.planeWar.Bullet;
import com.gjw.planeWar.EnemyPlane;
import com.gjw.planeWar.GameObject;
import com.gjw.planeWar.Props;

/**
 * @author gjw19
 * @date 2019/5/19
 */
public class BulletEnemyCollider implements Collider {
    private static final Props props = Props.getInstance();

    @Override
    public boolean collide(GameObject o1, GameObject o2) {
        if (o1 instanceof Bullet && o2 instanceof EnemyPlane) {
            Bullet b = (Bullet) o1;
            EnemyPlane e = (EnemyPlane) o2;
            if (b.getRect().intersects(e.getRect())) {
                e.die();
                b.die();
                props.SHOOT_ENEMY_NUM += 1;
                props.SCORE = props.SCORE + props.SCORE_DOUBLE;
                return false;
            }
        } else if (o1 instanceof EnemyPlane && o2 instanceof Bullet) {
            return collide(o2, o1);
        }
        return true;
    }
}
